package com.ruoyi.web.controller.loan.controller;

import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.loan.dto.PoorApplyDto;
import com.ruoyi.loan.dto.PoorStudentApplyDto;
import com.ruoyi.loan.dto.SelectPoorApplyDto;
import com.ruoyi.loan.entity.Image;
import com.ruoyi.loan.service.ImageService;
import com.ruoyi.loan.service.PoorApplyService;
import com.ruoyi.loan.service.UserService;
import com.ruoyi.loan.vo.SelectPoorApplyVo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author lin
 * @Date 2022/4/5 0:47
 */
@Controller
@RequestMapping("/loan/poor_apply")
public class PoorApplyController {

    @Resource
    private PoorApplyService poorApplyService;

    @Resource
    private UserService userService;

    @Autowired
    private ImageService imageService;

    @GetMapping()
    public String message(){
        String prefix = "loan/poor_apply";
        return prefix + "/poor_apply";
    }

    @GetMapping("/evidences")
    public String evidences(){
        String prefix = "loan/poor_apply";
        return prefix + "/evidences";
    }

    /**
     * 获取贫困生申请列表
     * @param applyDto 条件参数
     * @return 申请列表
     */
    @ResponseBody
    @GetMapping("/getPoorApplyList")
    public AjaxResult getPoorApplyList(SelectPoorApplyDto applyDto){
        PageInfo<SelectPoorApplyVo> poorApplyVoPageInfo = poorApplyService.selectPoorApplyList(applyDto);
        return AjaxResult.success(poorApplyVoPageInfo);
    }

    @ResponseBody
    @GetMapping("/getEvidences")
    public AjaxResult getEvidences(Integer loanId){
        List<Image> pageInfo = imageService.selectImagesByLoanId(loanId);
        return AjaxResult.success(pageInfo);
    }

    @ResponseBody
    @ApiOperation("贫困生申请")
    @PostMapping("/poorStudentApply")
    public AjaxResult poorStudentApply(@RequestBody PoorStudentApplyDto poorStudentApplyDto){
        userService.poorStudentApply(poorStudentApplyDto);
        return AjaxResult.success();
    }

    /**
     * 审核贫困生申请
     * @param dto 审核信息
     * @return 审核状态
     */
    @ResponseBody
    @PostMapping("/updateApply")
    public AjaxResult updateApply(@RequestBody PoorApplyDto dto){
        poorApplyService.updatePoorApply(dto);
        return AjaxResult.success();
    }


}
